package com.exchange.service.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.exchange.entity.pojo.ExchangeRecord;
import com.exchange.entity.pojo.User;
import com.exchange.entity.vo.ExchangeUserVo;
import com.exchange.mapper.ExchangeRecordMapper;
import com.exchange.service.ExchangeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【exchange_record】的数据库操作Service实现
* @createDate 2024-04-25 20:02:10
*/
@Service
public class ExchangeRecordServiceImpl extends ServiceImpl<ExchangeRecordMapper, ExchangeRecord>
    implements ExchangeRecordService{

    @Autowired
    private ExchangeRecordMapper exchangeRecordMapper;

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Override
    public Page<ExchangeUserVo> findAll(Integer offset, Integer pagesize,String token) {
        if (StrUtil.isBlank(token)){
            throw new RuntimeException("token不能为空");
        }
        String user = this.redisTemplate.opsForValue().get("user:login"+token);
        if (StrUtil.isBlank(user)){
            throw new RuntimeException("token无效");
        }
        User user1 = JSON.parseObject(user, User.class);
        Long id = user1.getId();
        Page<ExchangeUserVo> page = new Page<>(offset,pagesize);
        return this.exchangeRecordMapper.findAll(page,id);
    }

//    @Override
//    public Page<ExchangeUserVo> findAll(Integer offset, Integer pagesize) {
//        Page<ExchangeUserVo> page = new Page<>(offset,pagesize);
//        return this.exchangeRecordMapper.findAll(page);
//    }

}




